<template>
  <div class="app-container calendar-list-container">
    <div v-show="!opShow">
      <buttons :showQuery="true" :showBack="true" @query="doQuery" :list="btnList" :disabled="disabled" placeholder="" :permissions="permissions" @add="doAdd">
      </buttons>
      <grid :columns="columns" :multi="false" :url="queryUrl" ref="mainGrid" height="auto" diffHeight="155" @change="rowCilck" :queryEntity="queryEntity" :pagination="false"
        :permissions="permissions" @delete="doDelete"></grid>
    </div>
    <op ref="op" :visible="opShow" @cancel="cancel"></op>
  </div>
</template>

<script>
import request from '@/router/axios'
import url from '@/const/apiURL'
import grid from '@/components/Grid'
import buttons from '@/components/Buttons'
import op from './op'
import { Message, MessageBox } from 'element-ui'
import { initMenu } from "@/util/util";
import { resolveUrlPath } from "@/util/util";
import { mapGetters } from 'vuex'
import { YesOrNoFormatter } from '@/const/dict'

export default {
  components: { grid, buttons, op },
  data () {
    return {
      queryUrl: url.ADJUST_LIST_URL,
      disabled: true,
      opShow: false,
      billNo: '',
      queryEntity: { billNo: '' },
      columns: [
        {
          label: '操作', width: 80, prop: 'op', align: 'center', template: 'op', opList: [
            { name: '删除', clickName: 'delete', auth: 'adjuest_delete', confirm: true, showFomatter: function (row) { return row.status == 1 } }
          ]
        },
        { label: '调整单号', width: 180, prop: 'adjustNo', align: 'left' },
        { label: '对账单号', width: 180, prop: 'billNo', align: 'left' },
        { label: '客户名称', width: 180, prop: 'customerName', align: 'left' },
        { label: '金额', width: 120, prop: 'amount', align: 'center' },
        { label: '原因', width: 200, prop: 'remark', align: 'center' },
        { label: '创建人', width: 120, prop: 'createUserName', align: 'center' },
        { label: '创建时间', width: 100, prop: 'createTime', align: 'center' }
      ],
      btnList: [
        { name: '新增', type: 'primary', icon: 'edit', click: 'add', auth: 'adjuest_add', ctr: false },
        //{ name: '删除', type: 'primary', icon: 'edit', click: 'delete', auth: 'adjuest_delete', ctr: true, confirm: true }
      ]
    }
  },
  computed: {
    ...mapGetters([
      'permissions'
    ])
  },
  created () {
    this.queryEntity.billNo = this.$route.query.billNo
  },
  methods: {
    cancel () {
      this.opShow = false
    },
    doAdd () {
      this.opShow = true
      this.$refs['op'].init('新增', { billNo: this.queryEntity.billNo }, false, url.ADJUST_ADD_URL)
    },
    doDelete (row) {
      // const row = this.$refs.mainGrid.getSelectOne()
      if (row) {
        // 删除数据
        this.deleteOp(row.adjustNo).then((data) => {
          if (data) {
            this.$refs['mainGrid'].reload()
          }
        })
      }
    },
    doQuery (text) {
      this.$refs['mainGrid'].doQuery(text)
    },
    rowCilck (row) {
      this.disabled = row.length == 0
    },
    deleteOp (code) {
      return request({
        url: url.ADJUST_DELETE_URL,
        method: 'post',
        data: { 'key': 'key' },
        params: { 'adjustNo': code }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
